/*
 * flash.h
 *
 *  Created on: 2023年12月25日
 *      Author: Administrator
 */

#ifndef INC_FLASH_H_
#define INC_FLASH_H_

#include "main.h"
///*---------------------------------
//*BootLoad = 0x08000000 - 0x0800FFFF=64k
//*DownLoad = 0x08010000 - 0x0801FFFF=64k
//*APP	  = 0x08020000 - 0x0802FFFF=64k
//*Reserve  = 0x08030000 - 0x0803FFFF=64k
//*----------------2k=1page 64*page=128k----------------*/
/* 类型定义 ------------------------------------------------------------------*/
/* 宏定义 --------------------------------------------------------------------*/
/************************** STM32 内部 FLASH 配置 *****************************/
/* 私有类型定义 --------------------------------------------------------------*/
/* 私有宏定义 ----------------------------------------------------------------*/
#define STM32_FLASH_SIZE 256  //所选STM32的FLASH容量大小(单位为K)
#define STM32_FLASH_WREN 1    //使能 FLASH 写入(0，不是能;1，使能)

#if STM32_FLASH_SIZE<256
  #define STM_SECTOR_SIZE  1024 //字节
#else
  #define STM_SECTOR_SIZE	 2048
#endif


/* 扩展变量 ------------------------------------------------------------------*/
/* 函数声明 ------------------------------------------------------------------*/
uint16_t STMFLASH_ReadHalfWord(uint32_t faddr);		  //读出半字
void STMFLASH_WriteLenByte(uint32_t WriteAddr, uint32_t DataToWrite, uint16_t Len );	      //指定地址开始写入指定长度的数据
uint32_t STMFLASH_ReadLenByte(uint32_t ReadAddr, uint16_t Len );					                    	//指定地址开始读取指定长度数据
void STMFLASH_Write( uint32_t WriteAddr, uint64_t * pBuffer, uint16_t NumToWrite );		//从指定地址开始写入指定长度的数据
void STMFLASH_Read( uint32_t ReadAddr, uint16_t * pBuffer, uint16_t NumToRead );   	//从指定地址开始读出指定长度的数据
void Test_Write( uint32_t WriteAddr, uint64_t WriteData );                        //测试写入

//FLASH起始地址
#define STM32_FLASH_BASE 0x08000000 	//STM32 FLASH的起始地址
#define FLASH_WAITETIME  50000          //FLASH等待超时时间

//HAL_StatusTypeDef ProgramFlash(uint32_t Address, uint64_t* data,uint64_t dataLen);
uint32_t EraseFlash(uint32_t pageAddress, uint32_t numberPage);
uint32_t ReadFlash(uint32_t Address);


#endif /* INC_FLASH_H_ */
